home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Burning & Media / GB-PVR 1.2.13 / GBPVR10213.msi / Cabs.w1.cab / Global.asax.cs675 < prev    next >
Text File  |  2007-09-18  |  7KB  |  238 lines

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data.Common;
  5. using System.Data.OleDb;
  6. using System.Globalization;
  7. using System.Reflection;
  8. using System.Threading;
  9. using System.IO;
  10. using System.Xml;
  11. using System.Web;
  12. using System.Web.SessionState;
  13. using System.Web.UI.WebControls;
  14.  
  15. using GBPVR.Public;
  16. using GBPVRSchedule;
  17.  
  18. namespace gbweb
  19. {
  20.     /// <summary>
  21.     /// Summary description for Global.
  22.     /// </summary>
  23.     public class Global : System.Web.HttpApplication
  24.     {
  25.         /// <summary>
  26.         /// Required designer variable.
  27.         /// </summary>
  28.         private System.ComponentModel.IContainer components = null;
  29.  
  30.         public Global()
  31.         {
  32.             InitializeComponent();
  33.         }
  34.  
  35.         static Global()
  36.         {
  37.             lock (typeof(Schedule))
  38.             {
  39.                 // TODO: Make this a setting to switch between GBPVR and CDK scheduler
  40.                 settings = new Settings();
  41.                 Type scheduleType = Type.GetType("GBPVRSchedule." + Settings.schedule + "Schedule");
  42.                 schedule = scheduleType.InvokeMember(null, BindingFlags.CreateInstance, null, null, null) as Schedule;
  43.             }
  44.         }
  45.  
  46.         private static Schedule schedule;
  47.         public static Schedule Schedule
  48.         {
  49.             get
  50.             {
  51.                 return schedule;
  52.             }
  53.         }
  54.  
  55.         private static Settings settings;
  56.         public static Settings Settings
  57.         {
  58.             get
  59.             {
  60.                 return settings;
  61.             }
  62.         }
  63.  
  64.         public static XmlDocument Config
  65.         {
  66.             get
  67.             {
  68.                 if (HttpContext.Current.Session["config"] == null)
  69.                 {
  70.                     // find config.xml location
  71.                     string configFile = Path.Combine(Global.Settings.GetInstallDir(), "config.xml");
  72.                     // special check for sub's development machine
  73.                     if (File.Exists(configFile) == false)
  74.                     {
  75.                         if (File.Exists(@"c:\temp\config-master.dont-edit-me.xml"))
  76.                         {
  77.                             configFile = @"c:\temp\config-master.dont-edit-me.xml";
  78.                         }
  79.                         else
  80.                         {
  81.                             Logger.Error("Error finding config.xml");
  82.                         }
  83.                     }
  84.                     // load config
  85.                     XmlDocument configDoc = new XmlDocument();
  86.                     configDoc.Load(configFile);
  87.                     HttpContext.Current.Session["config"] = configDoc;
  88.                 }
  89.                 return (XmlDocument)HttpContext.Current.Session["config"];
  90.             }
  91.         }
  92.  
  93.         public static DbConnection GetOpenGBPVRDbConnection()
  94.         {
  95.             DbProviderFactory dbProviderFactory = DatabaseHelperFactory.getDbProviderFactory();
  96.             DbConnection dbConnect = dbProviderFactory.CreateConnection();
  97.             dbConnect.ConnectionString = DatabaseHelperFactory.getDbConnectionString();
  98.             dbConnect.Open();
  99.             return dbConnect;
  100.             
  101.         }
  102.  
  103.         public static void FillChannelList(DropDownList listChannels)
  104.         {
  105.             //Instantiate a schedule
  106.             Schedule scheduleHelper = Global.Schedule;
  107.  
  108.             //Pull in a list of shows to get a listing of available channels
  109.             IList listingsForPeriod;
  110.             listingsForPeriod = scheduleHelper.GetListingsForTimePeriod(DateTime.Now, DateTime.Now);
  111.  
  112.             //Load the channel list box with available channels
  113.             foreach (Channel channel in listingsForPeriod)
  114.             {
  115.                 listChannels.Items.Add(new ListItem(channel.getName(), channel.getOID().ToString()));
  116.             }
  117.         }
  118.  
  119.         public static void FillGenreList(Object GenreList)
  120.         {
  121.             // create the database connection
  122.             DbConnection aConnection = GetOpenGBPVRDbConnection();
  123.  
  124.             // create the command object and store the sql query
  125.             DbCommand aCommand = aConnection.CreateCommand();
  126.             aCommand.CommandText = "select genre_name from genre order by genre_name";
  127.             aCommand.Connection = aConnection;
  128.  
  129.             // create the datareader object to connect to table
  130.             DbDataReader aReader = aCommand.ExecuteReader();
  131.  
  132.             if (GenreList is ListBox)
  133.             {
  134.                 ListBox genreList = (ListBox)GenreList;
  135.  
  136.                 // iterate through the results to load the genre list
  137.                 while (aReader.Read())
  138.                 {
  139.                     genreList.Items.Add(aReader.GetString(0));
  140.                 }
  141.                 GenreList = genreList;
  142.             }
  143.             else
  144.             {
  145.                 DropDownList genreList = (DropDownList) GenreList;
  146.  
  147.                 // load the first record to the list for no preference
  148.                 genreList.Items.Add("Choose Genre...");
  149.  
  150.                 // iterate through the results to load the genre list
  151.                 while (aReader.Read())
  152.                 {
  153.                     genreList.Items.Add(aReader.GetString(0));
  154.                 }
  155.                 GenreList = genreList;
  156.             }
  157.  
  158.  
  159.             // close the reader
  160.             aReader.Close();
  161.  
  162.             // NB: close the connection
  163.             aConnection.Close();
  164.         }
  165. /*
  166.         protected void Application_Start(Object sender, EventArgs e)
  167.         {
  168.  
  169.         }
  170.  
  171.         protected void Session_Start(Object sender, EventArgs e)
  172.         {
  173.  
  174.         }
  175. */
  176.         protected void Application_BeginRequest(Object sender, EventArgs e)
  177.         {
  178.             if (Request.UserLanguages != null)
  179.             {
  180.                 Thread currentThread = Thread.CurrentThread;
  181.                 foreach (string language in Request.UserLanguages)
  182.                 {
  183.                     try
  184.                     {
  185.                         currentThread.CurrentCulture = new CultureInfo(language.Split(";".ToCharArray(), 2)[0]);
  186.                         break;
  187.                     }
  188.                     catch
  189.                     {
  190.                     }
  191.                 }
  192.                 currentThread.CurrentUICulture = currentThread.CurrentCulture;
  193.             }
  194.         }
  195. /*
  196.         protected void Application_EndRequest(Object sender, EventArgs e)
  197.         {
  198.  
  199.         }
  200.  
  201.         protected void Application_AuthenticateRequest(Object sender, EventArgs e)
  202.         {
  203.  
  204.         }
  205. */
  206.         protected void Application_Error(Object sender, EventArgs e)
  207.         {
  208.             // Log file ends up being C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\gbpvr\2364619e\429af7e1\assembly\dl2\07d20234\00d91a5d_07d7c401\<appdomain>.log
  209.             // Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName is not the best source for the log filename
  210.             // System.Reflection.Assembly.GetEntryAssembly();
  211.             // string logdir = AppDomain.CurrentDomain.BaseDirectory.Replace("/", @"\");
  212.             Logger.Error(Server.GetLastError().ToString());
  213.         }
  214. /*
  215.         protected void Session_End(Object sender, EventArgs e)
  216.         {
  217.  
  218.         }
  219.  
  220.         protected void Application_End(Object sender, EventArgs e)
  221.         {
  222.  
  223.         }
  224. */
  225.         #region Web Form Designer generated code
  226.         /// <summary>
  227.         /// Required method for Designer support - do not modify
  228.         /// the contents of this method with the code editor.
  229.         /// </summary>
  230.         private void InitializeComponent()
  231.         {
  232.             this.components = new System.ComponentModel.Container();
  233.         }
  234.         #endregion
  235.     }
  236. }
  237.  
  238.